<?php
class ShareAction extends PublicAction {
	public $className;
	public $uploadRoot;
	public $urlStr;
	
	public function init() {
		
		$this->className = __CLASS__;
		$this->urlStr = C ( 'URL' );
		$this->uploadRoot = C ( 'UPLOADS' );
	}
	
	/*
	 * 设置资源上传的目录
	 */
	public function setUpDire() {
		$this->init ();
		if ($pos = strrpos ( $this->className, 'Action' )) {
			$sustr = substr ( $this->className, 0, $pos );
		}
		
		$this->uploadRoot = $this->urlStr . '/' . $this->uploadRoot . '/' . $sustr . '/';
	}
	
	public function pictures() {
		
		if ($_POST ['sub2']) {
			
			switch (trim ( $_POST ['type1'] )) {
				case '1' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : '';
					
					$pictures = new Model ();
					$maxt = $pictures->query ( 'select max(uploadtime) as maxtime from qx_pictures where type=\'1\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'select * from qx_pictures where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'1\'';
					$selRel = $pictures->query ( $sql );
					
					$picture = D ( 'PictureView' );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					
					if ($selRel) {
						unset ( $pictures );
						$pictures = M ( 'Pictures' );
						$maps ['_string'] = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
						$maps ['type'] = '1';
						$retVal = $pictures->where ( $maps )->delete ();
						if ($retVal === false) {
							$this->error ( '数据清除失败!' );
							exit ();
						}
						
						if ($tftime < $tttime) {
							$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
							$map ['_string'] = $uploadtime;
							$list = $picture->where ( $map )->select ();
						}
						
						$list = $picture->where ( $map )->select ();
						if (! $list) {
							$this->success ( '但没有要同步的数据!' );
							exit ();
						}
					
					} else {
						
						if ($tftime < $tttime) {
							$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
							$map ['_string'] = $uploadtime;
							$list = $picture->where ( $map )->select ();
						}
						
						$list = $picture->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有数据需要同步!' );
							exit ();
						}
					
					}
					
					if ($selRel === false) {
						$this->error ( '数据操作失败!' );
						exit ();
					}
					
					$i = 0;
					
					unset ( $pictures );
					$pictures = M ( 'Pictures' );
					$tmp=new Model();
					foreach ( $list as $key => $val ) {
						
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						
						if (strpos ( $val ['url'], ',' ) && strpos ( $val ['area'], ',' )) {
							$urlArr = explode ( ',', $val ['url'] );
							$areaArr = explode ( ',', $val ['area'] );
							if (count ( $urlArr ) == count ( $areaArr )) {
								foreach ( $urlArr as $k => $v ) {
									
									$val ['url'] = $v;
									$val ['type'] = '1';
									$val ['status'] = '0';
									$val ['area'] = $areaArr [$k];
									$pictures->add ( $val );
								}
							}
						} else {
							$val ['status'] = '0';
							$val ['type'] = '1';
							$pictures->add ( $val );
						}
					}
					unset ( $map );
					$map ['type'] = '1';
					break;
				case '2' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : '';
					
					$image = D ( 'ImageView' );
					$pictures = new Model ();
					$maxt = $pictures->query ( 'select max(uploadtime) as maxtime from qx_pictures where type=\'2\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_pictures where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'2\'';
					$selRel = $pictures->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $image->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					}
					$i = 0;
					$pictures = M ( 'Pictures' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						
						if (strpos ( $val ['url'], ',' ) && strpos ( $val ['area'], ',' )) {
							$urlArr = explode ( ',', $val ['url'] );
							$areaArr = explode ( ',', $val ['area'] );
							if (count ( $urlArr ) == count ( $areaArr )) {
								foreach ( $urlArr as $k => $v ) {
									
									$val ['url'] = $v;
									$val ['type'] = '2';
									$val ['status'] = '0';
									$val ['area'] = $areaArr [$k];
									$pictures->add ( $val );
								}
							}
						} else {
							$val ['status'] = '0';
							$val ['type'] = '2';
							$pictures->add ( $val );
						}
					
					}
					unset ( $map );
					$map ['type'] = '2';
					break;
				case '3' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : '';
					
					$exhibit = D ( 'ExhibitsView' );
					$pictures = new Model ();
					$maxt = $pictures->query ( 'select max(uploadtime) as maxtime from qx_pictures where type=\'3\'' );
					$maxtime = $maxt [0] ['maxtime'];
					unset ( $pictures );
					$pictures = M ( 'Pictures' );
					$map ['uploadtime'] = array ('between', array ($tftime, $tttime ) );
					$sqlRet = $pictures->where ( $map )->delete ();
					unset ( $map );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					
					$map ['uploadtime'] = array ('between', array ($tftime, $tttime ) );
					
					if ($sqlRet !== false) {
						
						$list = $exhibit->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有同步数据!' );
							exit ();
						}
					
					} else {
						$this->error ( '数据操作失败!' );
						exit ();
					}
					
					$i = 0;
					$pictures = M ( 'Pictures' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						
						if (strpos ( $val ['url'], ',' ) && strpos ( $val ['area'], ',' )) {
							$urlArr = explode ( ',', $val ['url'] );
							$areaArr = explode ( ',', $val ['area'] );
							if (count ( $urlArr ) == count ( $areaArr )) {
								foreach ( $urlArr as $k => $v ) {
									
									$val ['url'] = $v;
									$val ['type'] = '3';
									$val ['status'] = '0';
									$val ['area'] = $areaArr [$k];
									$pictures->add ( $val );
								}
							}
						} else {
							$val ['status'] = '0';
							$val ['type'] = '3';
							$pictures->add ( $val );
						}
					
					}
					unset ( $map );
					$map ['type'] = '3';
					break;
				default :
			}
		
		} elseif ($_POST ['sub1']) {
			
			switch (trim ( $_POST ['type1'] )) {
				case '1' :
					$map ['type'] = '1';
					break;
				case '2' :
					$map ['type'] = '2';
					break;
				case '3' :
					$map ['type'] = '3';
					break;
				default :
					$map ['type'] = '1';
			}
			$pictures = new Model ();
			$maxt = $pictures->query ( 'select max(uploadtime) as maxtime from qx_pictures where type=\'' . $map ['type'] . '\'' );
			$maxtime = $maxt [0] ['maxtime'];
			
			unset ( $pictures );
			$pictures = M ( 'Pictures' );
			
			if (isset ( $_POST ['Num'] ) && ! empty ( $_POST ['Num'] )) {
				$map ['code'] = $_POST ['Num'];
				$this->assign ( 'num', $_POST ['Num'] );
			}
			if (isset ( $_POST ['ftime'] ) && ! empty ( $_POST ['ftime'] )) {
				$ftime = strtotime ( trim ( $_POST ['ftime'] ) );
				$uploadtime = 'uploadtime>=' . $ftime;
				$this->assign ( 'ftime', $ftime );
			}
			if (isset ( $_POST ['ttime'] ) && ! empty ( $_POST ['ttime'] )) {
				$ttime = strtotime ( trim ( $_POST ['ttime'] ) );
				$uploadtime .= ' and uploadtime<=' . $ttime;
				$this->assign ( 'ttime', $ttime );
			}
			if ($uploadtime) {
				$map ['_string'] = $uploadtime;
			}
		
		}
		
		if (! $pictures) {
			
			$pictures = new Model ();
			$maxt = $pictures->query ( 'select max(uploadtime) as maxtime from qx_pictures where type=\'1\'' );
			$maxtime = $maxt [0] ['maxtime'];
			unset ( $pictures );
			$pictures = M ( 'Pictures' );
			$map ['type'] = '1';
		
		}
		
		import ( "ORG.Util.Page" );
		$count = $pictures->where ( $map )->count ();
		$page = new page ( $count, 10 );
		$lists = $pictures->where ( $map )->limit ( $page->firstRow . "," . $page->listRows )->order ( 'uploadtime desc' )->select ();
		$this->assign ( "page", $page->show () );
		$this->assign ( 'list', $lists );
		//			echo $maxtime;
		$this->assign ( 'maxtime', $maxtime );
		$this->assign ( 'type', $map ['type'] );
		$this->Display ();
	
	}
	
	public function videos() {
		
		if ($_POST ['sub2']) {
			
			switch ($_POST ['type1']) {
				case '1' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : $this->error ( '请填写同步截止时间' );
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : $this->error ( '请填写同步起始时间' );
					
					$video = D ( 'VideoView' );
					$videos = new Model ();
					$maxt = $videos->query ( 'select max(uploadtime) as maxtime from qx_videos where type=\'1\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_videos where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'1\'';
					$selRel = $videos->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $video->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					unset ( $videos );
					$videos = M ( 'Videos' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						
						$val ['type'] = '1';
						$val ['status'] = '0';
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						$videos->add ( $val );
					}
					unset ( $map );
					$map ['type'] = '1';
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					break;
				case '2' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : $this->error ( '请填写同步截止时间' );
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : $this->error ( '请填写同步起始时间' );
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					
					$video = D ( 'FlashView' );
					$videos = new Model ();
					$maxt = $videos->query ( 'select max(uploadtime) as maxtime from qx_videos where type=\'2\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_videos where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'2\'';
					$selRel = $videos->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $video->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					
					unset ( $videos );
					$videos = M ( 'Videos' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						
						$val ['type'] = '2';
						$val ['status'] = '0';
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						$videos->add ( $val );
					}
					unset ( $map );
					$map ['type'] = '2';
					break;
				case '3' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( $_POST ['tttime'] ) : $this->error ( '请填写同步截止时间' );
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( $_POST ['tftime'] ) : $this->error ( '请填写同步起始时间' );
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					
					$video = D ( 'GameView' );
					$videos = new Model ();
					$maxt = $videos->query ( 'select max(uploadtime) as maxtime from qx_videos where type=\'3\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_videos where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'3\'';
					$selRel = $videos->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $video->where ( $map )->select ();
						if (! $list) {
							$this->error ( '没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					
					unset ( $videos );
					$videos = M ( 'Videos' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						
						$val ['type'] = '3';
						$val ['status'] = '0';
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						$videos->add ( $val );
					}
					unset ( $map );
					$map ['type'] = '3';
					break;
				default :
			}
		
		} elseif ($_POST ['sub1']) {
			
			$map ['type'] = ! empty ( $_POST ['type1'] ) ? trim ( $_POST ['type1'] ) : '';
			
			$videos = new Model ();
			$maxt = $videos->query ( 'select max(uploadtime) as maxtime from qx_videos where type=\'' . $map ['type'] . '\'' );
			$maxtime = $maxt [0] ['maxtime'];
			
			unset ( $videos );
			$videos = M ( 'Videos' );
			if (isset ( $_POST ['Num'] ) && ! empty ( $_POST ['Num'] )) {
				$map ['code'] = strtoupper ( $_POST ['Num'] );
				$this->assign ( 'num', $_POST ['Num'] );
			}
			if (isset ( $_POST ['ftime'] ) && ! empty ( $_POST ['ftime'] )) {
				$ftime = strtotime ( trim ( $_POST ['ftime'] ) );
				$uploadtime = 'uploadtime>=' . $ftime;
				$this->assign ( 'ftime', $ftime );
			} else {
				$this->error ( '请填写起始时间!' );
				exit ();
			}
			if (isset ( $_POST ['ttime'] ) && ! empty ( $_POST ['ttime'] )) {
				if (empty ( $_POST ['ftime'] )) {
					$this->error ( '您没有填写起始时间' );
				}
				$ttime = strtotime ( trim ( $_POST ['ttime'] ) );
				$uploadtime .= ' and uploadtime<=' . $ttime;
				$this->assign ( 'ttime', $ttime );
			} else {
				$this->error ( '请填写截止时间!' );
				exit ();
			
			}
			if ($uploadtime) {
				$map ['_string'] = $uploadtime;
			}
		
		}
		
		if (! $videos) {
			$videos = new Model ();
			$maxt = $videos->query ( 'select max(uploadtime) as maxtime from qx_videos where type=\'1\'' );
			$maxtime = $maxt [0] ['maxtime'];
			unset ( $videos );
			$videos = M ( 'Videos' );
			$map ['type'] = '1';
		}
		
		import ( "ORG.Util.Page" );
		$count = $videos->where ( $map )->count ();
		$page = new page ( $count, 10 );
		$lists = $videos->where ( $map )->limit ( $page->firstRow . "," . $page->listRows )->order ( 'uploadtime desc' )->select ();
		$this->assign ( "page", $page->show () );
		$this->assign ( 'list', $lists );
		$this->assign ( 'maxtime', $maxtime );
		
		$this->assign ( 'type', $map ['type'] );
		$this->display ();
	
	}
	
	public function articles() {
		if ($_POST ['sub2']) {
			
			switch ($_POST ['type1']) {
				case '1' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( trim ( $_POST ['tttime'] ) ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( trim ( $_POST ['tftime'] ) ) : '';
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					
					$article = D ( 'ArticleView' );
					$articles = new Model ();
					$maxt = $articles->query ( 'select max(uploadtime) as maxtime from qx_articles where type=\'1\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_articles where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'1\'';
					$selRel = $articles->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $article->where ( $map )->select ();
						if (! $list) {
							$this->error ( '这个时段没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					
					unset ( $articles );
					$articles = M ( 'Articles' );
					$tmp = new Model ();
					
					foreach ( $list as $key => $val ) {
						$val ['bookmark'] = 'author:' . $val ['author'];
						$val ['type'] = '1';
						$val ['status'] = '0';
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						$articles->add ( $val );
					}
					unset ( $map );
					$map ['type'] = '1';
					
					break;
				case '2' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( trim ( $_POST ['tttime'] ) ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( trim ( $_POST ['tftime'] ) ) : '';
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					
					$article = D ( 'BookView' );
					$articles = new Model ();
					$maxt = $articles->query ( 'select max(uploadtime) as maxtime from qx_articles where type=\'2\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_articles where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'2\'';
					$selRel = $articles->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $article->where ( $map )->select ();
						if (! $list) {
							$this->error ( '这个时段没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					
					unset ( $articles );
					$articles = M ( 'Articles' );
					$tmp = new Model ();
					foreach ( $list as $k => $v ) {
						$v ['type'] = '2';
						$v ['status'] = '0';
						if (trim ( $v ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $v ['cateid'] ) . '\'' );
							$v ['catename'] = $caten [0] ['catename'];
						} else {
							$v ['catename'] = '0';
						}
						$articles->add ( $v );
					}
					unset ( $tmp );
					unset ( $map );
					$map ['type'] = '2';
					break;
				case '3' :
					$tttime = ! empty ( $_POST ['tttime'] ) ? strtotime ( trim ( $_POST ['tttime'] ) ) : '';
					$tftime = ! empty ( $_POST ['tftime'] ) ? strtotime ( trim ( $_POST ['tftime'] ) ) : '';
					$this->assign ( 'tttime', $tttime );
					$this->assign ( 'tftime', $tftime );
					
					$article = D ( 'KnowledgeView' );
					$articles = new Model ();
					$maxt = $articles->query ( 'select max(uploadtime) as maxtime from qx_articles where type=\'2\'' );
					$maxtime = $maxt [0] ['maxtime'];
					$sql = 'delete from qx_articles where uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime . ' and type=\'2\'';
					$selRel = $articles->query ( $sql );
					$map ['is_dele'] = '0';
					$map ['status'] = '1';
					$uploadtime = 'uploadtime>=' . $tftime . ' and uploadtime<=' . $tttime;
					$map ['_string'] = $uploadtime;
					
					if ($selRel !== FALSE) {
						$list = $article->where ( $map )->select ();
						if (! $list) {
							$this->error ( '这个时段没有数据要同步!' );
							exit ();
						}
					} else {
						
						$this->error ( '数据库失败!' );
						exit ();
					
					}
					unset ( $articles );
					$articles = M ( 'Articles' );
					$tmp = new Model ();
					foreach ( $list as $key => $val ) {
						$val ['type'] = '3';
						$val ['status'] = '0';
						if (trim ( $val ['cateid'] ) > 0) {
							$caten = $tmp->query ( 'select catename from qx_category where cateid=\'' . trim ( $val ['cateid'] ) . '\'' );
							$val ['catename'] = $caten [0] ['catename'];
						} else {
							$val ['catename'] = '0';
						}
						
						$articles->add ( $val );
					}
					unset ( $map );
					$map ['type'] = '3';
					break;
				default :
					break;
			}
		
		} elseif ($_POST ['sub1']) {
			
			$map ['type'] = ! empty ( $_POST ['type1'] ) ? trim ( $_POST ['type1'] ) : '';
			
			$articles = new Model ();
			$maxt = $articles->query ( 'select max(uploadtime) as maxtime from qx_articles where type=\'' . $map ['type'] . '\'' );
			$maxtime = $maxt [0] ['maxtime'];
			
			unset ( $articles );
			$articles = M ( 'Articles' );
			if (isset ( $_POST ['Num'] ) && ! empty ( $_POST ['Num'] )) {
				$map ['code'] = strtoupper ( $_POST ['Num'] );
				$this->assign ( 'num', $_POST ['Num'] );
			}
			if (isset ( $_POST ['ftime'] ) && ! empty ( $_POST ['ftime'] )) {
				$ftime = strtotime ( trim ( $_POST ['ftime'] ) );
				$uploadtime = 'uploadtime>=' . $ftime;
				$this->assign ( 'ftime', $ftime );
			} else {
				$this->error ( '您没有填写起始时间' );
				exit ();
			}
			if (isset ( $_POST ['ttime'] ) && ! empty ( $_POST ['ttime'] )) {
				if (empty ( $_POST ['ftime'] )) {
					$this->error ( '您没有填写起始时间' );
					exit ();
				}
				$ttime = strtotime ( trim ( $_POST ['ttime'] ) );
				$uploadtime .= ' and uploadtime<=' . $ttime;
				$this->assign ( 'ttime', $ttime );
			} else {
				$this->error ( '您没有填写截止时间' );
				exit ();
			}
			if ($uploadtime) {
				$map ['_string'] = $uploadtime;
			}
		
		}
		
		if (! $articles) {
			
			$articles = new Model ();
			$maxt = $articles->query ( 'select max(uploadtime) as maxtime from qx_articles where type=\'1\'' );
			$maxtime = $maxt [0] ['maxtime'];
			unset ( $articles );
			$articles = M ( 'Articles' );
			$map ['type'] = '1';
		
		}
		
		import ( "ORG.Util.Page" );
		$count = $articles->where ( $map )->count ();
		$page = new page ( $count, 10 );
		$lists = $articles->where ( $map )->limit ( $page->firstRow . "," . $page->listRows )->order ( 'uploadtime desc' )->select ();
		$this->assign ( "page", $page->show () );
		$this->assign ( 'list', $lists );
		$this->assign ( 'maxtime', $maxtime );
		$this->assign ( 'type', $map ['type'] );
		$this->display ();
	
	}
	
	//发布图片
	public function sendpicture() {
		
		$id = $_POST ['id'];
		//获得前台资源id
		echo file_put_contents ( 'sendpicture.txt', $id );
	
	}
	//发布视频
	public function sendvideo() {
		
		$id = $_POST [id];
		echo file_put_contents ( 'sendvideo.txt', $id );
	
	}
	
	//发布文章
	public function sendarticle() {
		$id = $_POST [id];
		echo file_put_contents ( 'sendarticle.txt', $id );
	}

}